﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SiteManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load();
        }
        
    }

    private void load()
    {
        
        CategoryDAO1 ct = new CategoryDAO1();
        IList<Category1> list1 = (List<Category1>)ct.Get_CategoryName();
        grv_Category.DataSource = list1;
        grv_Category.DataBind();

    }

    protected void grv_Category_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grv_Category.EditIndex = e.NewEditIndex;
        load();
    }

    protected void grv_Category_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int cid = int.Parse(grv_Category.DataKeys[e.RowIndex].Value.ToString());
        string ct_name = ((TextBox)grv_Category.Rows[e.RowIndex].FindControl("txtName")).Text;
        CategoryDAO1 ct1 = new CategoryDAO1();

        int eff = ct1.Update_by_ID(cid, ct_name);
        if (eff > 0)
        {
            load();
            
        }
    }
    protected void grv_Category_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        grv_Category.EditIndex = -1;
        load();
    }
    protected void grv_Category_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }

    protected void grv_Category_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_Category.PageIndex = e.NewPageIndex;
        load();
    }
    protected void onCheckedChanged(object sender, EventArgs e)
    {
        if (((CheckBox)sender).Checked)
        {
            foreach (GridViewRow row in grv_Category.Rows)
            {
                ((CheckBox)row.FindControl("chk_item")).Checked = true;
            }
        }
        else
        {
            foreach (GridViewRow row in grv_Category.Rows)
            {
                ((CheckBox)row.FindControl("chk_item")).Checked = false;
            }
        }
    }
}